<template>
	<div class="main">
		<van-field label="危险作业类型" v-model="data.DangerOperateTypeName" name="title" readonly>
		</van-field>

		<van-field label="上报日期" v-model="data.ApplyDate" name="title" readonly>
		</van-field>

		<van-field label="位置" v-model="data.Location" name="title" readonly>
		</van-field>

		<van-field label="作业方" v-model="data.OperateObjName" name="title" readonly>
		</van-field>

        <van-field label="开始日期" v-model="data.StartDate" name="title" readonly>
		</van-field>

        <van-field label="结束日期" v-model="data.EndDate" name="title" readonly>
		</van-field>

        <van-field label="作业人员" v-model="data.OperateChnName" name="title" readonly>
		</van-field>

        <van-field label="监护人员" v-model="data.WatchMan" name="title" readonly>
		</van-field>



		<FileUpload
        @CallBack="_fileUploadCb"
        :attachs="data.Attachs"
        :labelName="'施工作业记录'"
        :allowEdit="false"
        />

        <FileUpload
        @CallBack="fileUploadCb"
        :RecordFile="data.ConstructionEndFile"
        :labelName="'施工结束资料'"
        :allowEdit="true"
      />
    <div class="bottom-btns">
        <van-button class="submit-btn" type="primary" @click="save()">
          提交
        </van-button>
      </div>

	</div>
</template>

<script>
import {
  UploadSubmit
} from "@/api/SitDangerOperateApplyrecordNew";

import FileListReadOnly from "../../../components/Attach/FileListReadOnlyYat.vue";
export default {
	components: { FileListReadOnly },
	data() {
		return {
			id: this.$route.query.id,
			data: {
				
			},
		}
	},
	beforeMount () {
		this.data = []

	},
	created() {
		this.getDetail();

	},
	activated() {},
    
	methods: {

    save() {
      if (!this.data.ConstructionEndFile) {
        return this.$toast("请上传施工结束资料!");
      }
      this.loading = true;
      let param = {
          ID : this.data.ID,
          DangerOperateType : this.data.DangerOperateType,
          DangerOperateTypeName : this.data.DangerOperateTypeName,
          ApplyDate : this.data.ApplyDate,
          Attachs : this.data.Attachs,
          StartDate : this.data.StartDate,
          EndDate : this.data.EndDate,
          Location : this.data.Location,
          OperateObj : this.data.OperateObj,
          OperateObjName : this.data.OperateObjName,
          OperateChnName : this.data.OperateChnName,
          WatchMan : this.data.WatchMan,
          status : this.data.status,
          ConstructionEndFile : this.data.ConstructionEndFile,
      };
      
      if (this.data.ID) {
        UploadSubmit(param)
          .then((res) => {
            this.$toast("保存成功");
            this.loading = false;
            setTimeout(() => {
              this.$router.goRefresh();
            }, 500);
          })
          .catch((err) => {
            console.log("err", err);
          });
        }
    },

    getDetail() {
        let params = { id: this.id };
        this.$axios
            .get('/SiteDangerOperateApplyRecordNew/GetDetail/{id}', { params: params })
            .then((res) => {
            res.data.DangerOperateTypeList.forEach((item) => {
                if (res.data.DangerOperateType == item.ID) {
                res.data.DangerOperateType = item.ID;
                  res.data.DangerOperateTypeName = item.Name;
                  }
                });
              this.SitdangerType  = res.data.DangerOperateType
            res.data.OperateObjList.forEach((item) => {
                if (res.data.OperateObj == item.ID) {
                res.data.OperateObj = item.ID;
                res.data.OperateObjName = item.Name;
                }
              });
              this.SitridoType  = res.data.OperateObj
             if(res.data.ApplyDate && res.data.ApplyDate.length > 10){
                  res.data.ApplyDate = res.data.ApplyDate.substring(0,10);			
              }

              if(res.data.StartDate && res.data.StartDate.length > 10){
                res.data.StartDate = res.data.StartDate.substring(0,10);
              }
              if(res.data.EndDate && res.data.EndDate.length > 10){
                res.data.EndDate = res.data.EndDate.substring(0,10);
              }
              if(res.data.CreateDate && res.data.CreateDate.length > 10){
                res.data.CreateDate = res.data.CreateDate.substring(0,10);
              }
              
              console.log(res.data.ApplyDate)

              this.data = res.data;
            });
    },
    _fileUploadCb(attachs) {
        this.data.Attachs = attachs;
    },
    fileUploadCb(RecordFile) {
        this.data.ConstructionEndFile = RecordFile;
    },
	},
}
</script>

<style lang="less" scoped>
.bottom-btns {
  margin-top: 10px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .submit-btn {
    width: 100%;
    height: 35px;
    font-size: 14px;
  }
}
</style>
